#########################################################################
##
## This file is part of the SAMRAI distribution.  For full copyright 
## information, see COPYRIGHT and LICENSE. 
##
## Copyright:     (c) 1997-2019 Lawrence Livermore National Security, LLC
## Description:   makefile for the restart database and HDF5 tests 
##
#########################################################################

SAMRAI        = @top_srcdir@
SRCDIR        = @srcdir@
SUBDIR        = source/test/restartdb
VPATH         = @srcdir@
TESTTOOLS     = ../testtools
OBJECT        = ../../..
REPORT        = $(OBJECT)/report.xml

CPPFLAGS_EXTRA =  -DTESTING=1

default: check

include $(OBJECT)/config/Makefile.config

NUM_TESTS = 5

TEST_NPROCS = @TEST_NPROCS@
QUOTE = \"

testHDF5: mainHDF5.o database_tests.o $(LIBSAMRAIDEPEND)
	$(CXX) $(CXXFLAGS) $(LDFLAGS) mainHDF5.o database_tests.o \
	$(LIBSAMRAI) $(LDLIBS) -o testHDF5

testHDF5AppFileOpen: mainHDF5AppFileOpen.o database_tests.o $(LIBSAMRAIDEPEND)
	$(CXX) $(CXXFLAGS) $(LDFLAGS) mainHDF5AppFileOpen.o database_tests.o \
	$(LIBSAMRAI) $(LDLIBS) -o testHDF5AppFileOpen

testSilo: mainSilo.o database_tests.o $(LIBSAMRAIDEPEND)
	$(CXX) $(CXXFLAGS) $(LDFLAGS) mainSilo.o database_tests.o \
	$(LIBSAMRAI) $(LDLIBS) -o testSilo

testSiloAppFileOpen: mainSiloAppFileOpen.o database_tests.o $(LIBSAMRAIDEPEND)
	$(CXX) $(CXXFLAGS) $(LDFLAGS) mainSiloAppFileOpen.o database_tests.o \
	$(LIBSAMRAI) $(LDLIBS) -o testSiloAppFileOpen

testMemory: mainMemory.o database_tests.o $(LIBSAMRAIDEPEND)
	$(CXX) $(CXXFLAGS) $(LDFLAGS) mainMemory.o database_tests.o \
	$(LIBSAMRAI) $(LDLIBS) -o testMemory

check:	testHDF5 testHDF5AppFileOpen testSilo testSiloAppFileOpen testMemory
	@for p in `echo "$(TEST_NPROCS)" | tr "," " "`; do \
	  echo "    <testcase classname=\"restartdb\" name=$(QUOTE)HDF5 $$p procs$(QUOTE)>" >> $(REPORT); \
	  $(OBJECT)/config/serpa-run $$p ./testHDF5 | $(TEE) foo; \
	  if ! grep "PASSED" foo >& /dev/null ; then echo "      <failure/>" >> $(REPORT); fi; \
	  echo "    </testcase>" >> $(REPORT); \
	done
	@for p in `echo "$(TEST_NPROCS)" | tr "," " "`; do \
	  echo "    <testcase classname=\"restartdb\" name=$(QUOTE)HDF5AppFilOpen $$p procs$(QUOTE)>" >> $(REPORT); \
	  $(OBJECT)/config/serpa-run $$p ./testHDF5AppFileOpen | $(TEE) foo; \
	  if ! grep "PASSED" foo >& /dev/null ; then echo "      <failure/>" >> $(REPORT); fi; \
	  echo "    </testcase>" >> $(REPORT); \
	done
	@for p in `echo "$(TEST_NPROCS)" | tr "," " "`; do \
	  echo "    <testcase classname=\"restartdb\" name=$(QUOTE)Silo $$p procs$(QUOTE)>" >> $(REPORT); \
	  $(OBJECT)/config/serpa-run $$p ./testSilo | $(TEE) foo; \
	  if ! grep "PASSED" foo >& /dev/null ; then echo "      <failure/>" >> $(REPORT); fi; \
	  echo "    </testcase>" >> $(REPORT); \
	done
	@for p in `echo "$(TEST_NPROCS)" | tr "," " "`; do \
	  echo "    <testcase classname=\"restartdb\" name=$(QUOTE)SiloAppFileOpen $$p procs$(QUOTE)>" >> $(REPORT); \
	  $(OBJECT)/config/serpa-run $$p ./testSiloAppFileOpen | $(TEE) foo; \
	  if ! grep "PASSED" foo >& /dev/null ; then echo "      <failure/>" >> $(REPORT); fi; \
	  echo "    </testcase>" >> $(REPORT); \
	done
	@for p in `echo "$(TEST_NPROCS)" | tr "," " "`; do \
	  echo "    <testcase classname=\"restartdb\" name=$(QUOTE)Memory $$p procs$(QUOTE)>" >> $(REPORT); \
	  $(OBJECT)/config/serpa-run $$p ./testMemory | $(TEE) foo; \
	  if ! grep "PASSED" foo >& /dev/null ; then echo "      <failure/>" >> $(REPORT); fi; \
	  echo "    </testcase>" >> $(REPORT); \
	done; \
	$(RM) foo

check2d:
	$(MAKE) check

check3d:
	$(MAKE) check

checkcompile: testHDF5 testHDF5AppFileOpen testSilo testSiloAppFileOpen \
	testMemory

checktest:
	$(RM) makecheck.logfile
	$(MAKE) check 2>&1 | $(TEE) makecheck.logfile
	$(TESTTOOLS)/testcount.sh $(TEST_NPROCS) $(NUM_TESTS) 0 makecheck.logfile
	$(RM) makecheck.logfile

examples:

perf:

everything:
	$(MAKE) checkcompile || exit 1
	$(MAKE) checktest
	$(MAKE) examples
	$(MAKE) perf

checkclean:
	$(CLEAN_COMMON_CHECK_FILES)
	$(RM) test_dir *.silo *.hdf5

clean: checkclean
	$(CLEAN_COMMON_TEST_FILES)
	$(RM) testHDF5 testHDF5AppFileOpen testSilo testSiloAppFileOpen \
	testMemory

include $(SRCDIR)/Makefile.depend
